// add-category.js
Page({
  data: {
    newCategoryName: ''
  },
  onCategoryInput: function(e) {
    this.setData({
      newCategoryName: e.detail.value
    });
  },
  addCategory: function() {
    const { newCategoryName } = this.data;
    if (newCategoryName.trim() === '') {
      wx.showToast({
        title: '分类名称不能为空',
        icon: 'none'
      });
      return;
    }
    const app = getApp();
    app.globalData.categories.push({ name: newCategoryName });
    wx.setStorageSync('categories', app.globalData.categories);
    wx.showToast({
      title: '分类添加成功',
      icon: 'success'
    });
    this.setData({
      newCategoryName: '' // 清空输入框
    });
    // 返回上一个页面
    wx.navigateBack();
    
  }
});
